package org.example.weather.bigscreen.core.api;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import org.example.weather.bigscreen.core.api.dto.BaiduWeatherDTO;
import org.example.weather.bigscreen.core.api.dto.WeatherInfoDTO;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * Created on 2022-07-22.
 *
 * @author chenyu
 */
@RestController
@RequestMapping("weather")
@Api(value = "天气信息", tags = {"天气信息"})
public interface WeatherApi {
    /**
     * 存储采集的天气信息
     * @param uploadTime 采集时间
     * @param weathers 天气信息
     * @return 更新数量
     */
    @PostMapping("upload")
    @ApiOperation(value = "存储采集的天气信息", httpMethod = "POST")
    @ApiResponse(code = 200, message = "接口返回成功")
    int upload(@RequestParam("uploadTime") @DateTimeFormat(pattern = "yyyyMMddHH") Date uploadTime, @RequestBody List<BaiduWeatherDTO> weathers);

    /**
     * 获取地区的天气信息,采集时间为空时代表查询最新采集的天气信息
     * @param uploadTime 采集时间
     * @param areaId 地区id
     * @return 地区的天气信息
     */
    @GetMapping("{areaId}/uploadTime")
    @ApiOperation(value = "获取地区的天气信息,采集时间为空时代表查询最新采集的天气信息", httpMethod = "GET")
    @ApiResponse(code = 200, message = "接口返回成功")
    WeatherInfoDTO select(@RequestParam(value = "uploadTime", required = false) @DateTimeFormat(pattern = "yyyyMMddHH") Date uploadTime, @PathVariable("areaId") String areaId);

    /**
     * 获取地区的天气信息排行
     * @param uploadTime 采集时间
     * @param label 天气标签 1: 温度 2:风力
     * @param sortRule 排序方向 0:asc 1:desc
     * @return 地区的天气信息排行
     */
    @GetMapping("{areaId}/{uploadTime}/top")
    @ApiOperation(value = "地区的天气信息排行", httpMethod = "GET")
    @ApiResponse(code = 200, message = "接口返回成功")
    List<WeatherInfoDTO> selectTop(@PathVariable("uploadTime") @DateTimeFormat(pattern = "yyyyMMddHH") Date uploadTime, @RequestParam("level") Integer label, @RequestParam("sortRule") Integer sortRule);

    /**
     * 获取天粒度采集的地区天气信息
     * @param uploadDate 采集时间
     * @param areaId 地区id
     * @return 天粒度地区天气信息
     */
    @GetMapping("{areaId}/{uploadDate}")
    @ApiOperation(value = "天粒度地区天气信息", httpMethod = "GET")
    @ApiResponse(code = 200, message = "接口返回成功")
    List<WeatherInfoDTO> selectDaily(@PathVariable("uploadDate") @DateTimeFormat(pattern = "yyyyMMdd") Date uploadDate, @PathVariable("areaId") String areaId);

    /**
     * 获取地区的历史天气信息
     * @param areaId 地区id
     * @return 获取地区的历史天气信息
     */
    @GetMapping("{areaId}")
    @ApiOperation(value = "获取地区的历史天气信息", httpMethod = "GET")
    @ApiResponse(code = 200, message = "接口返回成功")
    List<WeatherInfoDTO> selectHistory(@PathVariable("areaId") String areaId);

    /**
     * 获取时间窗口下地区天气信息
     * @param uploadTime 采集时间
     * @param areaIds 地区id列表
     * @return 获取时间窗口下地区天气信息
     */
    @PostMapping("{uploadTime}/weathers")
    @ApiOperation(value = "获取时间窗口下地区天气信息", httpMethod = "POST")
    @ApiResponse(code = 200, message = "接口返回成功")
    List<WeatherInfoDTO> selectMulti(@PathVariable("uploadTime") @DateTimeFormat(pattern = "yyyyMMddHH") Date uploadTime, @RequestBody List<String> areaIds);
}
